<template>
	<view class="">
		<view class="image-wh">
			<image :src="src" mode="widthFix"></image>
		</view>
		<view class="flexd-height"></view>
		<view class="flexd-button">
			<view class="" @click="GetImage">
				{{src?'重新上传':'去上传'}}
			</view>
			<view class="" @click="GetSubmit">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				src:'',
				BaseUrl:''
			}
		},
		methods:{
			GetImage(){
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: (res) => {
						this.uploadImage(res.tempFilePaths[0]);
					}
				});
			},
			uploadImage(tempFilePaths) {
				this.$http.upload(this.$config.UrlSignUpload, {
					filePath: tempFilePaths,
					name: 'file',
					formData: {},
				}).then((res) => {
					if (res.code == 1) {
						this.BaseUrl =  res.data.url
						this.src = this.$store.state.host + res.data.url
					} else this.$api.toast(res.msg);
				})
			},
			// 提交
			GetSubmit(){
				uni.$emit('yingzhang',this.BaseUrl)
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.flexd-height{
		height: 100rpx;
	}
	.flexd-button{
		position: fixed;
		height: 100rpx;
		bottom: 0;
		left: 0;
		background: #fff;
		display: flex;
		justify-content: space-around;
		width: 100%;
		align-items: center;
		view{
			width: 48%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 88rpx;
			color: #fff;
			border-radius: 44rpx;
			&:nth-of-type(1){
				background: #5B769F;
			}
			&:nth-of-type(2){
				background: #4A94E6;
			}
		}
	}
	.image-wh {
		image{
			width: 100%;
		}
	}
</style>